<html><head><title>RunProgram</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<font face="Arial" size="2"><p align="center"><b><font size="4">RunProgram()</font></b></p>
<p><b>Syntax</b></p><blockquote>
Result = <font color="#006666"><b>RunProgram</b></font>(Filename$ [, Parameter$, WorkingDirectory$ [, Flags [, SenderProgram]]])</blockquote>

</blockquote>
<b>Description</b><br><blockquote>

Launches an external program. 

</blockquote><p><b>Parameters</b></p><blockquote>
<style type="text/css">
table.parameters { border-spacing: 0px; border-style: none; border-collapse: collapse; }
table.parameters td { border-width: 1px; padding: 6px; border-style: solid; border-color: gray; vertical-align: top; font-family:Arial; font-size:10pt; }
</style>
<table width="90%" class="parameters">
<tr><td width="10%"><i>Filename$</i></td>
<td width="90%"> 
The executable name including its path. 

</td></tr>
<tr><td><i>Parameters$ (optional)</i></td>
<td> 
Specifies the command line parameters that will be passed to the program. 

</td></tr>
<tr><td><i>WorkingDirectory$ (optional)</i></td>
<td> 
Specifies the directory that will then be the current directory for the launched program. 

</td></tr>
<tr><td><i>Flags (optional)</i></td>
<td> 
It can be a combination (using '|' OR operator) of the following values: 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#924B72">#PB_Program_Wait</font>   : Wait until the launched program quits
  <font color="#924B72">#PB_Program_Hide</font>   : Launch the program in invisible mode
  <font color="#924B72">#PB_Program_Open</font>   : Open the program to communicate with it or get information about it.
  <font color="#924B72">#PB_Program_Read</font>   : Read the programs console output. (stdout)
  <font color="#924B72">#PB_Program_Write</font>  : Write to the input of the program. (stdin)
  <font color="#924B72">#PB_Program_Error</font>  : Read the error output of the program. (stderr)
  <font color="#924B72">#PB_Program_Connect</font>: Connect another programs output to this programs input.
</font></pre>

A program executed with <font color="#924B72">#PB_Program_Open</font> must be closed with <a href="closeprogram.html">CloseProgram()</a>. 
The 'Read', 'Write', 'Error' and 'Connect' flags require the <font color="#924B72">#PB_Program_Open</font> flag to be set as well. 
<br>
<br>
When using the <font color="#924B72">#PB_Program_Connect</font> flag, another program must have been started before with 
<font color="#924B72">#PB_Program_Open</font> and <font color="#924B72">#PB_Program_Read</font>. The number returned when running this 
program must be passed as the 'SenderProgram' parameter to RunProgram(). The output of the sender program will 
be sent directly to the input of the now executed program. Several programs may be connected in this way, 
to 'pipe' data through that group of connected programs. 
<br>
<br>
The following functions may be used with a program that has been executed with the <font color="#924B72">#PB_Program_Open</font> flag: 
<br>
<br>
- <a href="isprogram.html">IsProgram()</a>: check if the program number represents a valid program executed by RunProgram(). 
<br>
- <a href="programid.html">ProgramID()</a>: returns the OS ProcessID for the program. 
<br>
- <a href="programrunning.html">ProgramRunning()</a>: check if the program is still running. 
<br>
- <a href="waitprogram.html">WaitProgram()</a>: wait for the program to end. 
<br>
- <a href="killprogram.html">KillProgram()</a>: terminate the program. 
<br>
- <a href="programexitcode.html">ProgramExitCode()</a>: get the exitcode of the program. 
<br>
- <a href="closeprogram.html">CloseProgram()</a>: close the connection to the program. 
<br>
<br>
The following functions may be used for programs executed with the 'Read', 'Write' and 'Error' flags: 
<br>
<br>
- <a href="availableprogramoutput.html">AvailableProgramOutput()</a>: check if the programs output is available. 
<br>
- <a href="readprogramstring.html">ReadProgramString()</a>: read a string from the programs output. 
<br>
- <a href="readprogramdata.html">ReadProgramData()</a>: read data from the programs output. 
<br>
- <a href="readprogramerror.html">ReadProgramError()</a>: read a string from the programs error output. 
<br>
- <a href="writeprogramstring.html">WriteProgramString()</a>: write a string to the programs input. 
<br>
- <a href="writeprogramdata.html">WriteProgramData()</a>: write data to the programs input. 

</td></tr>
</table>
</blockquote><p><b>Return value</b></p><blockquote>

Nonzero if the program has been successfully launched, zero otherwise. 
<br>
<br>
If <font color="#924B72">#PB_Program_Open</font> was included in the Flags, the return-value is a number that 
identifies the program. It may be used in calls to get information about the program such as 
<a href="readprogramstring.html">ReadProgramString()</a> or <a href="programexitcode.html">ProgramExitCode()</a> 
or other functions mentioned above. 

</blockquote><p><b>Example</b></p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <font color="#006666">; Executes the PB compiler with the /? option and displays the output (windows version)</font>
  <font color="#006666">; For Linux/MacOS change the "/?" to "-h".</font>
  <font color="#006666">;</font>
  Compiler =<font color="#006666"> RunProgram</font>(<font color="#924B72">#PB_Compiler_Home</font>+"/Compilers/pbcompiler", "/?", "", <font color="#924B72">#PB_Program_Open</font> | <font color="#924B72">#PB_Program_Read</font>)
  Output$ = ""
  <b><font color="#006666">If</font></b> Compiler
    <b><font color="#006666">While</font></b> <font color="#006666">ProgramRunning</font>(Compiler)
      <b><font color="#006666">If</font></b> <font color="#006666">AvailableProgramOutput</font>(Compiler)
        Output$ +<font color="#006666"> ReadProgramString</font>(Compiler) +<font color="#006666"> Chr</font>(13)
      <b><font color="#006666">EndIf</font></b>
    <b><font color="#006666">Wend</font></b>
    Output$ +<font color="#006666"> Chr</font>(13) +<font color="#006666"> Chr</font>(13)
    Output$ + "Exitcode: " +<font color="#006666"> Str</font>(<font color="#006666">ProgramExitCode</font>(Compiler))
    
<font color="#006666">    CloseProgram</font>(Compiler) <font color="#006666">; Close the connection to the program</font>
  <b><font color="#006666">EndIf</font></b>
  
<font color="#006666">  MessageRequester</font>("Output", Output$)
</font></pre>

On Windows RunProgram() uses the default application associated with the file type of the given file. 
An example: RunProgram("Test.html") will open the web browser, which is generally used for displaying 
web sites on your system. 

</Blockquote><p><b>Supported OS </b><Blockquote>All</Blockquote></p><center><- <a href=removeenvironmentvariable.html>RemoveEnvironmentVariable()</a> - <a href=index.html>Process Index</a> - <a href=setenvironmentvariable.html>SetEnvironmentVariable()</a> ->

</body></html>